package com.hy.erp.inventory.service;

import java.util.List ;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

/*import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
*/
import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.NationDao;
import com.hy.erp.inventory.dao.interfaces.INationDao;
import com.hy.erp.inventory.pojo.Nation;
import com.hy.erp.inventory.pojo.interfaces.INation;
import com.hy.erp.inventory.service.interfaces.INationService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午10:23:39</li>
 * <li>类型名称：NationalitiesService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
/*@ Name ( "nationalitiesService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
*/
@Component("nationService")
public class NationService extends AbstractBusinessService < NationDao> implements INationService
{
	
	
	private INationDao nationDao=null;
	
	@Resource(name="nationDao")
	public void setNationDao(INationDao nationDao) {
		this.nationDao = nationDao;
	}

	@ Override
	public boolean addNationalities (
										Nation nationalities )
	{





		if ( null == nationalities )
		{
			return true ;
		}

		else
		{
			//System.out
				//	.println("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh");

//			INationDao nationDao = (INationDao) this
	//				.getDao(INation.class);

			return nationDao.persist(nationalities);
		}

	
	
	
	
	}

	@ Override
	public boolean modifyNationalities (
											Nation nationalities )
	{





		if ( ( null == nationalities )
				|| ( null == nationalities
											.getIdentifier ( ) )
				|| ( nationalities
									.getIdentifier ( )
									.trim ( )
									.length ( ) == 0 ) )
		{
			return true ;
		}
		else
		{

		//	INationDao nationDao =
		//		( INationDao ) this
			//								.getDao ( INation.class ) ;



			if ( null == nationalities )
			{
				throw new ArchitectureFoundationException (
															"修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}

			return ( nationDao
									.merge ( nationalities ) != null ) ;
		}

	
	
	
	
	}

	@ Override
	public Integer removeNationalities (
											String [ ] nationalitiesIds )
	{


		if ( ( null == nationalitiesIds )
				|| ( nationalitiesIds.length == 0 ) )
		{
			return new Integer (
									0 ) ;
		}
		else
		{

		//	INationDao nationDao =
			//	( INationDao ) this
		//									.getDao ( INation.class ) ;

			return nationDao
									.remove ( nationalitiesIds ) ;
	}
	
	
	
	}

	@ Override
	public String [ ] addNationalities (
											Object [ ] nationalities )
	{

		if ( null == nationalities )
		{
			return null ;
		}

		else
		{
			
		///	INationDao nationDao =
		//										( INationDao ) this
			//																.getDao ( INation.class ) ;

			Nation[] nationalitiess=new Nation[nationalities.length];
						for(int i=0;i<nationalities.length;i++)
						{
							Nation nationalities2=( Nation ) nationalities[i];
							nationalitiess[i]=nationalities2;
						}
						return nationDao
						                .persist ( nationalitiess ) ;
			
		}

	
	
	
	
	
	}

	@ Override
	public List < Nation > getAllNationalities ( )
	{

		//INationDao nationDao =
		//	( INationDao ) this
		//								.getDao ( INation.class ) ;

		return nationDao
								.find ( ) ;
	}

	@ Override
	public String [ ] modifyNationalities (
											Object [ ] objects )
	{
		if (  null == objects ) 
		{
			return null;
		}
		else
		{
		////	INationDao nationDao =
		//		( INationDao ) this
			//								.getDao ( INation.class ) ;
			Nation[] types=new Nation[objects.length];
            for(int i=0;i<objects.length;i++)
            {
            	Nation type=( Nation ) objects[i];
            	types[i]=type;
            }
			
			return nationDao.merge ( types );
		}
	}

}
